package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.AcDetailActivity;
import com.example.administrator.yuejian_2.bean.ActivitySearchBean;
import com.example.administrator.yuejian_2.viewholder.SearchVH;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/25.
 */

public class SearchAdapter extends RecyclerView.Adapter{
    private List<ActivitySearchBean> searchlist = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public SearchAdapter(Context context,List<ActivitySearchBean> searchlist){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.searchlist.addAll(searchlist);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_search,parent,false);
        SearchVH holder = new SearchVH(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SearchVH searchholder = (SearchVH) holder;
        ActivitySearchBean searchBean = searchlist.get(position);

        final String name = searchBean.getA_name();
        searchholder.aname.setText(name);

        final int aid = searchBean.getAid();
        final int cost = searchBean.getA_money();
        searchholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AcDetailActivity.class);
                intent.putExtra("aid",aid);
                intent.putExtra("cost",cost);
                intent.putExtra("activityName",name);
                context.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return searchlist.size();
    }
}
